import type { App } from 'vue'
import type { ICustomWindow } from '@/plugin/naive-ui'
import to from 'await-to-js'

export const setupGlobalProperties = (app: App<Element>) => {
  app.config.globalProperties.$to = to
  app.config.globalProperties.$message = (window as unknown as ICustomWindow)['$message']
  app.config.globalProperties.$notification = (window as unknown as ICustomWindow)['$notification']
  app.config.globalProperties.$dialog = (window as unknown as ICustomWindow)['$dialog']
  app.config.globalProperties.$loadingBar = (window as unknown as ICustomWindow)['$loadingBar']
}

export const commonApiWithOutComponent = () => {
  const message = (window as unknown as ICustomWindow)['$message']
  const notification = (window as unknown as ICustomWindow)['$notification']
  const dialog = (window as unknown as ICustomWindow)['$dialog']
  const loadingBar = (window as unknown as ICustomWindow)['$loadingBar']

  return {
    to,
    message,
    notification,
    dialog,
    loadingBar
  }
}
